// pages/more/more.js
var util = require("../../utils/util.js")
var api = require("../../utils/api.js")
var app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        type: 0,
        articel: [],
        test: [],
        uresclass: [],
        page: 1,
    },
    jump: function(e) {
        wx.navigateTo({
            url: '../wptext/wptext?id=' + e.currentTarget.dataset.id + '&type=' + e.currentTarget.dataset.type,
        })
    },
    theid: function(e) {
        wx.navigateTo({
            url: '../thetext/thetext?id=' + e.currentTarget.id,
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        var that = this
        that.setData({
            type: options.type
        })
        console.log(that.data.type)
        var info = {
            type: 0
        }
        var url = app.u.HOME_URL + app.u.ARTICELIST
        api.requestUrl(info, url).then(res => {
            console.log(res.data)
            if (res.code == 200) {
                that.setData({
                    articel: res.data
                })
            }
        })
        var info1 = {}
        var url1 = app.u.HOME_URL + app.u.GETTESTLIST
        api.requestUrl(info1, url1).then(res => {
            console.log(res.data)
            that.setData({
                test: res.data
            })
        })
        var info2 = {}
        var url2 = app.u.HOME_URL + app.u.GETCLASSLIST
        api.requestUrl(info2, url2).then(res => {
            console.log(res.data)
            that.setData({
                uresclass: res.data
            })
        })
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {
        var that = this
        var newpage = that.data.page + 1
        that.setData({
            page: newpage
        })

        if (that.data.type == 1) {
            var info = {
                page: newpage,
            }
            var url = app.u.HOME_URL + app.u.GETTESTLIST
            api.requestUrl(info, url).then(res => {
                console.log(res.data)
                if (res.code == 200) {
                    that.setData({
                        test: that.data.test.concat(res.data)
                    })
                }

            })
        } else if (that.data.type == 2) {
            var info = {
                page: newpage,
            }
            var url = app.u.HOME_URL + app.u.GETCLASSLIST
            api.requestUrl(info, url).then(res => {
                console.log(res.data)
                if (res.code == 200) {
                    that.setData({
                        uresclass: that.data.uresclass.concat(res.data)
                    })
                }

            })
        } else if (that.data.type == 3) {
            var info = {
                page: newpage,
                type: 0,
            }
            var url = app.u.HOME_URL + app.u.ARTICELIST
            api.requestUrl(info, url).then(res => {
                console.log(res.data)
                if (res.code == 200) {
                    that.setData({
                        articel: that.data.articel.concat(res.data)
                    })
                }
            })
        }
    },

})